﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using XMLGener.Data;
using XMLGener.interfaces;

namespace XMLGener.GUI.components
{
    /// <summary>
    /// 
    /// </summary>
    public partial class XGeneratedFileSelector : UserControl, IXModuleField
    {
        /// <summary>
        /// 
        /// </summary>
        public XGeneratedFileSelector()
        {
            InitializeComponent();
        }
                /// <summary>
        /// 
        /// </summary>
        /// <param name="param"></param>
        public void setAttr(XModuleParam param)
        {
            this.label1.Text = param.name;
            this.id = param.id;
            
        }


        private string id = null;
        private XMLGenerNode node = null;
        private XMLGenerDocument doc = null;

        #region IXModuleField Members

        /// <summary>
        /// Set source nodes
        /// </summary>
        /// <param name="node"></param>
        public void setXNode(XMLGenerNode node)
        {
            this.node = node;
            if (node != null)
            {
                this.doc = node.ownerDocument;
                this.comboBox1.Items.Clear();
                this.comboBox1.Items.AddRange(doc.getPreGeneratedIds().ToArray());
                String val = node.getSetting(id);
                this.comboBox1.SelectedItem=node.getSetting(id);
            }
            else
            {
                doc = null;
            }


        }


        #endregion

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (node != null)
                node.setSetting(id,comboBox1.SelectedItem as String);
        }

      
    }
}
